# app/api/common/exceptions.py

from fastapi import HTTPException
from typing import Any, Dict, Optional

class CustomHTTPException(HTTPException):
    """自定义HTTP异常"""
    
    def __init__(
        self,
        status_code: int,
        detail: str,
        error_code: Optional[str] = None,
        extra_data: Optional[Dict[str, Any]] = None
    ):
        super().__init__(status_code=status_code, detail=detail)
        self.error_code = error_code
        self.extra_data = extra_data or {}

class FileProcessingError(CustomHTTPException):
    """文件处理错误"""
    
    def __init__(self, detail: str, file_path: Optional[str] = None):
        super().__init__(
            status_code=422,
            detail=detail,
            error_code="FILE_PROCESSING_ERROR",
            extra_data={"file_path": file_path}
        )

class VectorizationError(CustomHTTPException):
    """向量化错误"""
    
    def __init__(self, detail: str, model_name: Optional[str] = None):
        super().__init__(
            status_code=500,
            detail=detail,
            error_code="VECTORIZATION_ERROR",
            extra_data={"model_name": model_name}
        )

class DatabaseError(CustomHTTPException):
    """数据库错误"""
    
    def __init__(self, detail: str, operation: Optional[str] = None):
        super().__init__(
            status_code=500,
            detail=detail,
            error_code="DATABASE_ERROR",
            extra_data={"operation": operation}
        )

class ModelError(CustomHTTPException):
    """模型错误"""
    
    def __init__(self, detail: str, model_type: Optional[str] = None):
        super().__init__(
            status_code=500,
            detail=detail,
            error_code="MODEL_ERROR",
            extra_data={"model_type": model_type}
        )

class TaskError(CustomHTTPException):
    """任务错误"""
    
    def __init__(self, detail: str, task_id: Optional[str] = None):
        super().__init__(
            status_code=500,
            detail=detail,
            error_code="TASK_ERROR",
            extra_data={"task_id": task_id}
        ) 